/*******************************************************************************
 * This file is part of Crunch Graphics.
 *
 * Crunch Graphics is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later version.
 *
 * Crunch Graphics is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with
 * Crunch Graphics.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/

package com.crunch.graphics.gpu;

/** Base class for GPU objects.
 *
 *  This class should not be directly accessed, as methods are not virtual.
 *  Objects should derive from it for the convenience of GpuState access.
 */
public class GpuObject {
	/** Stores a reference to the GpuState.
	 */
	public GpuObject(GpuState state) {
		gpuState = state;
	}

	/** Returns the underlying GpuState.
	 */
	public GpuState getGpuState() {
		return gpuState;
	}

	/** Enables or disables the given state and returns the new state.
	 */
	boolean setStateEnabled(boolean newState, boolean currentState, int stateName) {
		return setStateEnabled(getGpuState(), newState, currentState, stateName);
	}

	/** Enables or disables the given state and returns the new state.
	 */
	static boolean setStateEnabled(GpuState state, boolean newState, boolean currentState, int stateName) {
		if (newState && !currentState) {
			state.getGl().glEnable(stateName);
		} else if (!newState && currentState) {
			state.getGl().glDisable(stateName);
		}
		return newState;
	}

	// underlying GPU state
	private GpuState gpuState;
}